package com.foodndate.food.taste;

	
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.foodndate.food.member.MemberDao;
import com.foodndate.food.member.MemberDto;

	@Controller
	@RequestMapping("/taste")
	public class TasteController {
		@Autowired private MemberDao memberdao;
		@Autowired private TasteDao tastedao;
		//맛집 가입 페이지
		@RequestMapping(value="/tasteJoin" ,method=RequestMethod.GET)
		public String tasteJoin(){
			System.out.println("taste");
			return "taste/tasteJoin";
		}
		//맛집 가입 아이디 중복체크
		@RequestMapping(value="/chk",method=RequestMethod.GET)
		public String chk(String id,TasteDto tastedto){
			System.out.println("중복확인 폼이동 확인");
			System.out.println("클라이언트 id값 :" +id);
		
			int b=tastedao.chk(id);
			System.out.	println("foodid : " +b);
			int a=memberdao.chk(id);
			System.out.println("sssss");
			if(b ==0){
				System.out.println("ssss");
				if(a==0){
				System.out.println("사용가능아이디 ");
				}else {
					System.out.println("사용 불가능 아이디");
				}
			}else{
			System.out.println("사용불가능 아이디");
			}
			return "member/chk";
					
		}
		//맛집 가입 처리
		@RequestMapping(value="/joinprocess" ,method=RequestMethod.GET)
		public String joinprocess(TasteDto tastedto){
			System.out.println("기업가입성공");
			System.out.println("taste : pw  : " + tastedto.getFood_pw());
			int b=tastedao.chk(tastedto.getFood_id());
			System.out.	println("foodid : " +b);
			int a=memberdao.chk(tastedto.getFood_id());
			System.out.println("sssss");
			if(b ==0){
				System.out.println("ssss");
				if(a==0){
				System.out.println("사용가능아이디 ");
				}else {
					System.out.println("사용 불가능 아이디");
			     return "member/main";
				}
			}else{
			System.out.println("사용불가능 아이디");
			return "member/main";
			}
			tastedao.joinprocess(tastedto);
			return "member/main";
		}
		//로그인 페이지 이동
		@RequestMapping(value="/login",method=RequestMethod.GET)
		public String login(){
			System.out.println("로그인 페이지");
		return "taste/login";
		}
		//로그인 프로세스
		@RequestMapping(value="/loginprocess",method=RequestMethod.GET)
		public String loginprocee(String login_id,String login_pw,TasteDto tastedto,HttpSession session, Model model){
			tastedto.setFood_id(login_id);
			tastedto.setFood_pw(login_pw);
			int su=tastedao.login(tastedto);
			System.out.println("로그인 아이디 : "+tastedto.getFood_id());
			System.out.println("로그인 pw : " + tastedto.getFood_pw());
			System.out.println("su : " + su);
			model.addAttribute("su", su);
			
			
			if(su==1){session.setAttribute("sessionId", tastedto.getFood_id());
				return "taste/test";
			}else{
				model.addAttribute("su","아이디 ./ 비밀번호 확인요청");
				return "taste/login";
			}
			
		}
		//회원 수정전 회원정보 불러오기
		@RequestMapping(value="/detail",method=RequestMethod.GET)
		public String detail(HttpSession session,TasteDto tastedto,Model model){

			System.out.println("디테일");
			String id=(String)session.getAttribute("sessionId");
			System.out.println("세션 겟 아이디  : " + id);
			tastedto.setFood_id(id);
			
			tastedto=tastedao.info(tastedto);
			System.out.println("detail : infoid   " + tastedto.getFood_id());
			System.out.println("detail : infopw   " + tastedto.getFood_pw());
			System.out.println("detail : infoname   " + tastedto.getFood_name());
			model.addAttribute("info", tastedto);
					
			return "taste/modify";
		}
	
		//회원 수정 하기
		@RequestMapping(value="/updateprocess",method=RequestMethod.GET)
		public String updateprocess(TasteDto tastedto){
			System.out.println("update됨");
			int su = tastedao.updateprocess(tastedto);
			if(su == 0 ){
				System.out.println("업데이트 실패");
			}else{
				System.out.println("업데이트 성공");
			}
			return "member/test";
		
			
		}	
		//회원 삭제/탈퇴하기
		@RequestMapping(value="/delete",method=RequestMethod.GET)
		public String delete(HttpSession session,TasteDto tastedto){
			String id=(String) session.getAttribute("sessionId");
			tastedto.setFood_id(id);
			tastedao.delete(tastedto);
		    
			return "member/main";
		
		}
		//맛집 관리 리스트
		@RequestMapping(value="/tastelist",method=RequestMethod.GET)
		public String list(TasteDto tastedto,Model model){
			
			List tastelist=tastedao.list(tastedto);
			System.out.println("멤버 리스트" + tastelist.size());
			model.addAttribute("tastelist", tastelist);
			return "taste/list";
		}
		//어드민 회원 삭제
		@RequestMapping(value="/admindel",method=RequestMethod.GET)
		public  String admindel(int num){
			System.out.println("taste삭제할 번호"+num);
			tastedao.admindel(num);
			return "redirect:tastelist";
		}
}

	
	